package com.sky.mapper;

import com.sky.dto.OrdersStatusAllDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author yangkexuan
 * @className OrderMapper
 * @date 2023/6/13 14:07
 * @description
 */
@Mapper
public interface OrderMapper {
    /**
     * 插入数据
     * @param order
     */
    void insert(Orders order);

    /**
     * 根据用户ID查询用户有哪些订单
     * @return
     */
    @Select("select * from orders where user_id = #{userId} and status = #{status}")
    List<Orders> orderByUserId(Long userId,Integer status);

    /**
     * 历史订单查询
     * @param orders
     * @return
     */
    List<Orders> selectList(Orders orders);

    /**
     * 查询单个订单信息
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders selectListById(Long id);

    /**
     * 判断当前订单状态
     * @param id
     * @return
     */
    @Select("select count(*) from orders where status in(1,2,3,4) and id = #{id}")
    Integer selectOrderStatus(Long id);

    /**
     * 修改订单状态
     * @param ordersStatusAllDTO
     */
    void updateCancelOrder(OrdersStatusAllDTO ordersStatusAllDTO);

    /**
     * 查询各个订单状态
     * @return
     */

    OrderStatisticsVO selectStatistics(LocalDateTime begin ,LocalDateTime end);

    /**
     * 订单状态判断
     * 1.获取超过15分钟未支付的订单的id
     * 2.每天获取一次状态为派送中的订单的id
     * @param status
     * @param time
     * @return
     */
    List<Long> selectPayTime(Integer status, LocalDateTime time);

    /**
     * 根据订单号查询当前用户的订单
     * @param orderNumber
     * @param userId
     * @return
     */
    @Select("select * from orders where number = #{orderNumber} and user_id = #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单支付状态
     * @param ordersUpdate
     */
    void update(Orders ordersUpdate);
}
